<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>添加计时终端</title>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/public.js"></script>
<script type="text/javascript" src="../../js/validata.js"></script>
<script type="text/javascript" src="../../js/alert.js"></script>
<script type="text/javascript" src="../../js/loadSchoolGrade.js"></script>
<script type="text/javascript" src="../../js/jquery-ui/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../js/jquery-ui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css">
</head>
<body>
	<div class="right_mainH4">
		<p>
			添加计时终端 <small>Control panel</small>
		</p>
	</div>
	<div>
		<form id="form1">
			<table class="table table-bordered .table-condensed">
				<tr>
					<td>编号:</td>
					<td></td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td>培训机构:</td>
					<td id="schools"></td>
					<td>教练车:</td>
					<td>
						<select name="addCheZaiDevice.car" id="car" class="required" style="width: 160px;">
							<option value="请选择">请选择</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>终端类型:</td>
					<td>
						<select name="termtype" style="width: 140px;">
							<option value="1">车载计程计时终端</option>
							<option value="2">课堂教学计时终端</option>
							<option value="3">模拟训练计时终端</option>
						</select>
					</td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td>手机号:</td>
					<td>						 
						<input type="text" name="mobile" class="required phone"/>
					</td>
					<td>生产厂家:</td>
					<td>
						<input type="text" name="vender" class="required maxlength:50" />
					</td>
				</tr>
				<tr>
					<td>终端型号:</td>
					<td>
						<input type="text" name="model" class="required maxlength:150" />
					</td>
					<td>IMEI:</td>
					<td>
						<input type="text" name="imei" class="required conlength:15" maxlength="15"/>
					</td>
				</tr>
				<tr>
					<td>MAC:</td>
					<td>
						<input type="text" name="mac" class="required maxlength:50"/>
					</td>
					<td>SN:</td>
					<td>
						<input type="text" name="sn" class="required maxlength:50" />
					</td>
				</tr>
				<tr>
					<td>固件版本号:</td>
					<td>
						<input type="text" name="fedition" class="required maxlength:50" />
					</td>
					<td>软件版本号:</td>
					<td>
						<input type="text" name="sedition" class="required maxlength:50" />
					</td>
				</tr>
				<tr>
					<td>SIM卡号:</td>
					<td>
						<input type="text" name="sim" class="required maxlength:50"/>
					</td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td colspan="5" style="text-align: center;">
						<button type="button" onclick="addCheZai();" class="btn btn-info">添加</button>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
     <!-- 上传学员头像 -->
     <div id="uploadImgDiv" style="display:none;" title="头像上传">
     	<iframe src="" style="width:100%;height: 100%" frameborder="no" marginwidth="0" marginheight="0" allowtransparency="yes"></iframe>
     </div>
     
    <script type="text/javascript">
		$(function(){
			var storage = window.sessionStorage;
		    var schools = storage.getItem("schools");//获取存在sessionStorage里的驾校数据
		    if(schools != null){
		    	var schoolHtml;
		    	schoolHtml = '<select name="addCheZaiDevice.school" id="school"  class="required" style="width: 160px;" onchange="findCars();">';
		    	schoolHtml += schools;
		    	schoolHtml += '</select>';
		    	$("#schools").html(schoolHtml);
		    }
		});
		
		//获得驾校的未绑定终端的教练车
		function findCars(){
			var schoolId = $("#school").val();
			if(isNull(schoolId)){
        		$.ajax({
        			url : "../../coachCar/findSchoolCar.ao",
        			type : 'POST',
        			data :{
        				id : schoolId
        			},
        			cache : false,
        			dataType : "json",
        			success : function(data) {
        				if(data["state"] == "success"){
        					var carHtml = '<option value="请选择">请选择</option>';
        					for(var i = 0; i < data["result"].length; i++){
            					carHtml += "<option value='"+data["result"][i]["id"]+"'>"+data["result"][i]["licnum"]+"</option>";
        					}
        			    	$("#car").html(carHtml);
        				}
        			}
        		});
			}else{
				$("#cars").html("");
			}
		}
		
    	//添加车载终端信息
    	function addCheZai(){
    		/* var car = $("#car").val();

			$("#car").parent().find("span[class='errorCar']").remove();
    		if(!isNull(car)){
    			var span = "<span class='errorCar'>请选择需要绑定的教练车</span>";
    			$("#car").parent().append(span);
    		}else{
    			$("#car").parent().find("span").remove();
    		}
    		 */
    		if(validata("form1")){
        		$.ajax({
        			url : "../../cheZai/add.ao",
        			type : 'POST',
        			data :$("#form1").serialize(),
        			cache : false,
        			beforeSend : ajaxstar,
        			complete : ajaxend,
        			dataType : "json",
        			success : function(data) {
    					sAlert(data["result"]);
        				if(data["state"] == "success"){
        					clearTable("form1");
        				}
        			}
        		});
    		}
    	}
    </script>
</body>
</html>